import { ElMessage, ElMessageBox } from 'element-plus'

/**
 * 统一消息封装
 * 约定：所有消息默认显示关闭按钮，统一时长，集中入口
 */
const DEFAULT_DURATION = 2000

export const notify = {
  success(message: string, duration: number = DEFAULT_DURATION) {
    ElMessage.success({ message, showClose: true, duration })
  },

  error(message: string, duration: number = DEFAULT_DURATION + 500) {
    ElMessage.error({ message, showClose: true, duration })
  },

  warning(message: string, duration: number = DEFAULT_DURATION + 500) {
    ElMessage.warning({ message, showClose: true, duration })
  },

  info(message: string, duration: number = DEFAULT_DURATION) {
    ElMessage.info({ message, showClose: true, duration })
  },

  /**
   * 确认框封装
   */
  confirm(message: string, title: string = '提示', options: Record<string, unknown> = {}) {
    return ElMessageBox.confirm(message, title, {
      type: 'warning',
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      ...options,
    })
  },

  /**
   * HTML 内容提示框（用于错误详情等富文本）
   */
  alertHtml(html: string, title: string = '提示', options: Record<string, unknown> = {}) {
    return ElMessageBox.alert(html, title, {
      dangerouslyUseHTMLString: true,
      confirmButtonText: '确定',
      ...options,
    })
  },
}

export default notify
